<?php

namespace app\admin\controller;

use app\BaseController;

class Common extends BaseController
{
    public $payType = [
        1 => "在线支付",
        2 => "微信支付",
        3 => "货到付款",
    ];

    public $pay_status = [
        0 => "未支付",
        1 => "已支付",
        2 => "已退款",
        3 => "部分退款",
    ];

    public $status = [
        1 => "已确认/未支付",
        2 => "已支付/待发货",
        3 => "已发货",
        4 => "已完成",
        5 => "已取消",
        6 => "已关闭",
    ];

    public function getTree($arr,$pid = 0,$lev = 0){
        //数组循环一遍，谁的parent值等于$pid，谁就是它儿子
        static $subs = array();
        foreach($arr as &$v){
            //就要把儿子的$pid传过来，看儿子的id里面有没有孙子
            if($v['pid'] == $pid){
                $v['level']=$lev;
                $v['name'] = str_repeat('----',$lev).$v['name'];
                $subs[] = $v;
                $this->getTree($arr,$v['id'],$lev+1);
            }
        }
        return $subs;
    }



    public function getParents($categorys,$pId = 0,$l=0){
        $list =array();
        foreach ($categorys as $k=>$v){
            if ($v['pid'] == $pId){
                unset($categorys[$k]);
                if ($l < 2){
                    //小于三级
                    $v['children'] = $this->getParents($categorys,$v['id'],$l+1);
                }
                $list[] = $v;
            }
        }
        return $list;

    }
}